import * as PIXI from 'pixi.js'
import { typeModule } from '@renderer/utils/bundle'
import { TYPE } from '@renderer/config'
import useDiyStore from '@renderer/store/modules/useDiyStore'
import { getPixiData, setPixi } from '@renderer/store/modules/usePixiStore'
import param from '../param'
export default async (): Promise<PIXI.Container<PIXI.ContainerChild>> => {
  const diyStore = useDiyStore()
  const container = new PIXI.Container()
  await Promise.all(
    Object.entries(TYPE).map(async ([key]) => {
      const typeContainerData = getPixiData(param.value.typeKey[key]) // 类型数据
      const sprite = await typeModule({
        type: key,
      } as Wx.Card.Param)
      sprite.anchor.set(0.5)
      sprite.visible = diyStore.creationData.type === key
      typeContainerData.rightType = sprite.uid // 将类型与右侧关联
      setPixi(sprite.uid, sprite)
      container.addChild(sprite)
    }),
  )
  return container
}
